<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="../../../../lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.useso.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="../../../../lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="../../../../css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="../../../../images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="../../../../images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="../../../../images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="../../../../images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="k8s集群搭建,">










<meta name="description" content="1.创建一个测试用的deployment[root@linux-node1 ~]# kubectl run net-test --image=alpine --replicas=3 sleep 360000 2.查看创建情况[root@linux-node1 ~]# kubectl get pods -o wide NAME                        READY     STA">
<meta name="keywords" content="k8s集群搭建">
<meta property="og:type" content="article">
<meta property="og:title" content="07-K8s集群搭建---创建K8s应用">
<meta property="og:url" content="http://demo_demo.gitee.io/2018/06/03/07k8s-ji-qun-da-jianchuang-jiank8s-ying-yong/index.html">
<meta property="og:site_name" content="运维人">
<meta property="og:description" content="1.创建一个测试用的deployment[root@linux-node1 ~]# kubectl run net-test --image=alpine --replicas=3 sleep 360000 2.查看创建情况[root@linux-node1 ~]# kubectl get pods -o wide NAME                        READY     STA">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-12-10T06:42:10.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="07-K8s集群搭建---创建K8s应用">
<meta name="twitter:description" content="1.创建一个测试用的deployment[root@linux-node1 ~]# kubectl run net-test --image=alpine --replicas=3 sleep 360000 2.查看创建情况[root@linux-node1 ~]# kubectl get pods -o wide NAME                        READY     STA">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://demo_demo.gitee.io/2018/06/03/07k8s-ji-qun-da-jianchuang-jiank8s-ying-yong/">





  <title>07-K8s集群搭建---创建K8s应用 | 运维人</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/guomaoqiu" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#FD6C6C; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">运维人</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">生命在于折腾</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://demo_demo.gitee.io">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OutMan">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维人">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">07-K8s集群搭建---创建K8s应用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-03T10:28:32+08:00">
                2018-06-03
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="../../../../categories/虚拟化-amp-云计算-amp-大数据/" itemprop="url" rel="index">
                    <span itemprop="name">虚拟化&amp;云计算&amp;大数据</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="1-创建一个测试用的deployment"><a href="#1-创建一个测试用的deployment" class="headerlink" title="1.创建一个测试用的deployment"></a>1.创建一个测试用的deployment</h3><pre><code>[root@linux-node1 ~]# kubectl run net-test --image=alpine --replicas=3 sleep 360000
</code></pre><h3 id="2-查看创建情况"><a href="#2-查看创建情况" class="headerlink" title="2.查看创建情况"></a>2.查看创建情况</h3><pre><code>[root@linux-node1 ~]# kubectl get pods -o wide
NAME                        READY     STATUS    RESTARTS   AGE       IP            NODE
net-test-5767cb94df-6crmr   1/1       Running   0          17s       10.2.97.176   192.168.56.13
net-test-5767cb94df-9mpmb   1/1       Running   0          17s       10.2.70.187   192.168.56.12
net-test-5767cb94df-x8l44   1/1       Running   0          17s       10.2.97.175   192.168.56.13

# 使用kubectl创建了一个名为net-test 的deployment, 镜像是alpine 副本数为3，
[root@linux-node1 ~]# kubectl get deployments
NAME       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
net-test   3         3         3            3           7m
</code></pre><h3 id="3-测试联通性"><a href="#3-测试联通性" class="headerlink" title="3.测试联通性"></a>3.测试联通性</h3><pre><code>ping 10.2.97.176
</code></pre><h2 id="通过yaml文件部署应用"><a href="#通过yaml文件部署应用" class="headerlink" title="通过yaml文件部署应用"></a>通过yaml文件部署应用</h2><h3 id="1-编写一个nginx-deployment-yaml文件"><a href="#1-编写一个nginx-deployment-yaml文件" class="headerlink" title="1.编写一个nginx-deployment.yaml文件:"></a>1.编写一个nginx-deployment.yaml文件:</h3><pre><code>[root@linux-node1 ~]# cat &gt;  nginx-deployment.yaml  &lt;&lt; EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.10.3
        ports:
        - containerPort: 80
   EOF
</code></pre><h3 id="2-执行创建"><a href="#2-执行创建" class="headerlink" title="2.执行创建:"></a>2.执行创建:</h3><pre><code>[root@linux-node1 ~]# kubectl create -f nginx-deployment.yaml
deployment.apps &quot;nginx-deployment&quot; created

# 查看deployment
[root@linux-node1 ~]# kubectl get deployment/nginx-deployment
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   10        10        10           10          1m

# 查看deployment 详情
[root@linux-node1 ~]# kubectl describe deployment/nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Thu, 31 May 2018 20:20:17 +0800
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision=1
Selector:               app=nginx
Replicas:               10 desired | 10 updated | 10 total | 10 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.10.3
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  &lt;none&gt;
    Mounts:       &lt;none&gt;
  Volumes:        &lt;none&gt;
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  &lt;none&gt;
NewReplicaSet:   nginx-deployment-75d56bb955 (10/10 replicas created)
Events:
  Type    Reason             Age               From                   Message
  ----    ------             ----              ----                   -------
  Normal  ScalingReplicaSet  5m                deployment-controller  Scaled up replica set nginx-deployment-75d56bb955 to 3
  Normal  ScalingReplicaSet  1m (x2 over 3m)   deployment-controller  Scaled down replica set nginx-deployment-75d56bb955 to 3
  Normal  ScalingReplicaSet  57s (x3 over 5m)  deployment-controller  Scaled up replica set nginx-deployment-75d56bb955 to 10

# 查看pod ,可以看出按照我们的描述文件里面的副本数已经有10个POD通过Schedule到了不同的node节点上面
[root@linux-node1 ~]# kubectl get pod -o wide
NAME                                READY     STATUS    RESTARTS   AGE       IP            NODE
net-test-5767cb94df-6crmr           1/1       Running   0          40m       10.2.97.178   192.168.56.13
net-test-5767cb94df-9mpmb           1/1       Running   0          40m       10.2.70.187   192.168.56.12
net-test-5767cb94df-x8l44           1/1       Running   0          40m       10.2.97.177   192.168.56.13
nginx-deployment-75d56bb955-255w2   1/1       Running   0          3m        10.2.70.196   192.168.56.12
nginx-deployment-75d56bb955-5ckvs   1/1       Running   0          8m        10.2.70.188   192.168.56.12
nginx-deployment-75d56bb955-7dq87   1/1       Running   0          3m        10.2.70.198   192.168.56.12
nginx-deployment-75d56bb955-8vl7p   1/1       Running   0          3m        10.2.97.191   192.168.56.13
nginx-deployment-75d56bb955-9f9ms   1/1       Running   0          3m        10.2.97.189   192.168.56.13
nginx-deployment-75d56bb955-9g9bk   1/1       Running   0          3m        10.2.97.188   192.168.56.13
nginx-deployment-75d56bb955-9kz2r   1/1       Running   0          3m        10.2.70.197   192.168.56.12
nginx-deployment-75d56bb955-s78gs   1/1       Running   0          8m        10.2.70.189   192.168.56.12
nginx-deployment-75d56bb955-v8n5v   1/1       Running   0          3m        10.2.97.190   192.168.56.13
nginx-deployment-75d56bb955-zfb4m   1/1       Running   0          8m        10.2.97.179   192.168.56.13

# 查看某个pod详情
[root@linux-node1 ~]# kubectl describe pod/nginx-deployment-75d56bb955-255w2
Name:           nginx-deployment-75d56bb955-255w2
Namespace:      default
Node:           192.168.56.12/192.168.56.12
Start Time:     Thu, 31 May 2018 20:24:31 +0800
Labels:         app=nginx
                pod-template-hash=3181266511
Annotations:    &lt;none&gt;
Status:         Running
IP:             10.2.70.196
Controlled By:  ReplicaSet/nginx-deployment-75d56bb955
Containers:
  nginx:
    Container ID:   docker://48ad80730efd6d744ac6d31b34778eb8e75b0f4c6698e1c1fc8f6046a6a77b2b
    Image:          nginx:1.10.3
    Image ID:       docker-pullable://nginx@sha256:6202beb06ea61f44179e02ca965e8e13b961d12640101fca213efbfd145d7575
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Thu, 31 May 2018 20:24:33 +0800
    Ready:          True
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-5htws (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          True
  PodScheduled   True
Volumes:
  default-token-5htws:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-5htws
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     &lt;none&gt;
Events:
  Type    Reason                 Age   From                    Message
  ----    ------                 ----  ----                    -------
  Normal  SuccessfulMountVolume  3m    kubelet, 192.168.56.12  MountVolume.SetUp succeeded for volume &quot;default-token-5htws&quot;
  Normal  Pulled                 3m    kubelet, 192.168.56.12  Container image &quot;nginx:1.10.3&quot; already present on machine
  Normal  Created                3m    kubelet, 192.168.56.12  Created container
  Normal  Started                3m    kubelet, 192.168.56.12  Started container
  Normal  Scheduled              2m    default-scheduler       Successfully assigned nginx-deployment-75d56bb955-255w2 to 192.168.56.12


# 访问Nginx pod
[root@linux-node1 ~]# curl -I http://10.2.70.196
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Thu, 31 May 2018 12:30:45 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 31 Jan 2017 15:01:11 GMT
Connection: keep-alive
ETag: &quot;5890a6b7-264&quot;
Accept-Ranges: byte

# 更新deployment
[root@linux-node1 ~]# kubectl set image  deployment/nginx-deployment nginx=nginx:1.12.2 --record
deployment.apps &quot;nginx-deployment&quot; image updated

# 可以看到更新已经成功(滚动更新)
[root@linux-node1 ~]# kubectl get deployment/nginx-deployment -o wide
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES         SELECTOR
nginx-deployment   10        10        10           10          17m       nginx        nginx:1.12.2   app=nginx

[root@linux-node1 ~]# curl -I 10.2.97.192
HTTP/1.1 200 OK
Server: nginx/1.12.2   # 版本已经更新成功
Date: Thu, 31 May 2018 12:35:54 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 11 Jul 2017 13:29:18 GMT
Connection: keep-alive
ETag: &quot;5964d2ae-264&quot;
Accept-Ranges: bytes

# 查看deployment更新历史
[root@linux-node1 ~]# kubectl rollout history deployment/nginx-deployment
deployments &quot;nginx-deployment&quot;
REVISION  CHANGE-CAUSE
1         &lt;none&gt; # 用于在之前在创建创建nginx deployment的时候 未加参数 --record 所以这个信息为none
2         kubectl set image deployment/nginx-deployment nginx=nginx:1.12.2 --record=true

# 查看版本详情(--revison=VERSION_NUM)
[root@linux-node1 ~]# kubectl rollout history deployment/nginx-deployment --revision=1
deployments &quot;nginx-deployment&quot; with revision #1
Pod Template:
  Labels:   app=nginx
    pod-template-hash=3181266511
  Containers:
   nginx:
    Image:  nginx:1.10.3
    Port:   80/TCP
    Host Port:  0/TCP
    Environment:    &lt;none&gt;
    Mounts: &lt;none&gt;
  Volumes:  &lt;none&gt;

# 版本回滚至上一个版本:
[root@linux-node1 ~]# kubectl rollout undo deployment/nginx-deployment
deployment.apps &quot;nginx-deployment&quot;

[root@linux-node1 ~]# kubectl get deployment/nginx-deployment -o wide
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES         SELECTOR
nginx-deployment   10        10        10           10          26m       nginx        nginx:1.10.3   app=nginx

# 扩容pod数量
[root@linux-node1 ~]# kubectl scale --replicas=20 deployment nginx-deployment
deployment.extensions &quot;nginx-deployment&quot; scaled

[root@linux-node1 ~]# kubectl get deployment/nginx-deployment -o wide
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES         SELECTOR
nginx-deployment   20        20        20           20          28m       nginx        nginx:1.10.3   app=nginx
</code></pre><p>那问题来了:</p>
<ol>
<li>每次收到获取podIP太扯了，总不能每次都要手动改程序或者配置才能访问服务吧，要怎么提前知道podIP呢？</li>
<li>Pod在运行中可能会重建，IP变了怎么解？</li>
<li>如何在多个Pod中实现负载均衡嘞？</li>
</ol>
<p>这些问题使用k8s Service就可以解决。</p>
<p>Service可以将pod IP封装起来，即使Pod发生重建，依然可以通过Service来访问Pod提供的服务。此外，Service还解决了负载均衡的问题，大家可以多访问几次Service，然后通过kubectl logs 来查看Nginx Pod的访问日志来确认</p>
<h3 id="创建一个对于nginx-deployment的一个service"><a href="#创建一个对于nginx-deployment的一个service" class="headerlink" title="创建一个对于nginx deployment的一个service"></a>创建一个对于nginx deployment的一个service</h3><h4 id="1-编写nginx-service-yaml文件"><a href="#1-编写nginx-service-yaml文件" class="headerlink" title="1.编写nginx-service.yaml文件"></a>1.编写nginx-service.yaml文件</h4><pre><code>[root@linux-node1 ~]# cat &gt; nginx-service.yaml &lt;&lt; EOF
kind: Service 
apiVersion: v1
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
EOF
</code></pre><h4 id="2-执行创建操作"><a href="#2-执行创建操作" class="headerlink" title="2.执行创建操作:"></a>2.执行创建操作:</h4><pre><code>[root@linux-node1 ~]# kubectl create -f nginx-service.yaml
service &quot;nginx-service&quot; created

[root@linux-node1 ~]# kubectl get service -o wide
NAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE       SELECTOR
kubernetes      ClusterIP   10.1.0.1       &lt;none&gt;        443/TCP   3d        &lt;none&gt;
nginx-service   ClusterIP   10.1.146.223   &lt;none&gt;        80/TCP    30s       app=nginx

# 访问VIP
[root@linux-node1 ~]# curl -I http://10.1.146.223
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Thu, 31 May 2018 12:54:54 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 31 Jan 2017 15:01:11 GMT
Connection: keep-alive
ETag: &quot;5890a6b7-264&quot;
Accept-Ranges: bytes

# 在节点2上查看LVS，通过k8s封装LVS来实现了负载均衡
[root@linux-node2 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -&gt; RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.1.0.1:443 rr persistent 10800
  -&gt; 192.168.56.11:6443           Masq    1      1          0
TCP  10.1.146.223:80 rr
  -&gt; 10.2.70.204:80               Masq    1      0          0
  -&gt; 10.2.70.205:80               Masq    1      0          1
  -&gt; 10.2.70.206:80               Masq    1      0          0
  -&gt; 10.2.70.207:80               Masq    1      0          0
  -&gt; 10.2.70.208:80               Masq    1      0          0
  -&gt; 10.2.70.209:80               Masq    1      0          0
  -&gt; 10.2.70.210:80               Masq    1      0          0
  -&gt; 10.2.70.211:80               Masq    1      0          0
  -&gt; 10.2.70.212:80               Masq    1      0          0
  -&gt; 10.2.70.213:80               Masq    1      0          0
  -&gt; 10.2.97.197:80               Masq    1      0          0
  -&gt; 10.2.97.198:80               Masq    1      0          0
  -&gt; 10.2.97.199:80               Masq    1      0          1
  -&gt; 10.2.97.200:80               Masq    1      0          0
  -&gt; 10.2.97.201:80               Masq    1      0          0
  -&gt; 10.2.97.202:80               Masq    1      0          1
  -&gt; 10.2.97.203:80               Masq    1      0          1
  -&gt; 10.2.97.204:80               Masq    1      0          0
  -&gt; 10.2.97.205:80               Masq    1      0          0
</code></pre>
      
    </div>
    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>


  
</div>
    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="../../../../tags/k8s集群搭建/" rel="tag"># k8s集群搭建</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="../../02/06k8s-ji-qun-da-jianflannel-wang-luo-bu-shu/" rel="next" title="06-K8s集群搭建---Flannel网络部署">
                <i class="fa fa-chevron-left"></i> 06-K8s集群搭建---Flannel网络部署
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="../08k8s-ji-qun-da-jiancoredns-chuang-jiandashboard/" rel="prev" title="08-K8s集群搭建---CoreDNS创建&DashBoard">
                08-K8s集群搭建---CoreDNS创建&DashBoard <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png" alt="OutMan">
            
              <p class="site-author-name" itemprop="name">OutMan</p>
              <p class="site-description motion-element" itemprop="description">😊</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="../../../../archives/">
              
                  <span class="site-state-item-count">79</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="../../../../categories/index.html">
                  <span class="site-state-item-count">22</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="../../../../tags/index.html">
                  <span class="site-state-item-count">46</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/guomaoqiu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i></a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:guomaoqiu@google.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i></a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-创建一个测试用的deployment"><span class="nav-number">1.</span> <span class="nav-text">1.创建一个测试用的deployment</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-查看创建情况"><span class="nav-number">2.</span> <span class="nav-text">2.查看创建情况</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-测试联通性"><span class="nav-number">3.</span> <span class="nav-text">3.测试联通性</span></a></li></ol><li class="nav-item nav-level-2"><a class="nav-link" href="#通过yaml文件部署应用"><span class="nav-number"></span> <span class="nav-text">通过yaml文件部署应用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-编写一个nginx-deployment-yaml文件"><span class="nav-number">1.</span> <span class="nav-text">1.编写一个nginx-deployment.yaml文件:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-执行创建"><span class="nav-number">2.</span> <span class="nav-text">2.执行创建:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#创建一个对于nginx-deployment的一个service"><span class="nav-number">3.</span> <span class="nav-text">创建一个对于nginx deployment的一个service</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-编写nginx-service-yaml文件"><span class="nav-number">3.1.</span> <span class="nav-text">1.编写nginx-service.yaml文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-执行创建操作"><span class="nav-number">3.2.</span> <span class="nav-text">2.执行创建操作:</span></a></li></ol></li></ol></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OutMan</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="../../../../lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="../../../../js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="../../../../js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="../../../../js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="../../../../js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="../../../../js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
